package handler

import (
	"github.com/gin-gonic/gin"
	"guafo/internel/errs"
	"guafo/internel/service"
	"guafo/internel/types"
	"guafo/pkg/ginl/wrap_gin"
)

// @Description
// @Author 代码小学生王木木

type CodeHandler struct {
	svc service.ICaptchaSvc
	types.Res
}

func NewCodeHandler(svc service.ICaptchaSvc) *CodeHandler {
	return &CodeHandler{
		svc: svc,
		Res: types.Res{},
	}
}

func (h *CodeHandler) ImageCaptcha(ctx *gin.Context) (wrap_gin.Result, error) {
	id, path, err := h.svc.MakeCaptcha()
	if err != nil {
		return h.ErrX(errs.ImgCaptchaError), err
	}
	res := types.CaptchaResponse{
		CaptchaID: id,
		PicPath:   path,
	}
	return h.SuccesJson(res), nil
}
